home *** CD-ROM | disk | FTP | other *** search
- Path: hubcap.clemson.edu!hubcap!mjs
- From: mjs@hubcap.clemson.edu (M. J. Saltzman)
- Newsgroups: comp.lang.c
- Subject: Re: NEwbie: How to return a multi-dimensional array from function?
- Date: 15 Mar 96 20:53:00 GMT
- Organization: Clemson University
- Message-ID: <mjs.826923180@hubcap>
- References: <4hp273$8bu@news.xs4all.nl> <31404CE9.1A4A@mc.net> <mjs.826298629@hubcap> <4ib78s$6gv@news.bridge.net> <4ic3p3$cl5@news.xs4all.nl> <4ic8pj$c99@news.bridge.net>
- NNTP-Posting-Host: hubcap.clemson.edu
- X-Newsreader: NN version 6.5.0 #1
-
- psycho@bridge.net (Gary Thompson) writes:
-
- |falstaff@xs4all.nl (Falstaff) wrote:
-
- |>[...]
-
- |>If you declare a function
-
- |>int *demo(void)
- |>{ static int n=0;
- |> n++;
- |> return &n;
- |>}
-
- |>the caller can use the static variable until the next time your function
- |>is called. This is how the standard library function tmpnam() returns,
- |>for example.
-
- |Well, of course it will work in your example... you returned the value. Try
- |this...
-
- No he didn't. He returned the *address*. That's what I did in my original
- response.
-
- |main()
- |{
- | foo();
- | n++;
- |}
-
- |foo()
- |{
- | static int n=0;
- | n=1;
- |}
-
- |This will give you a compile error. You cannot use N outside of foo() which was
- |the point I was making. However, if you called foo again, N will be 1 before it
- |get's re-assigned to 1.
-
- Of course it will. But the point you were making is moot, since the
- technique I used in the post you responded to was the same as
- Falstaff's.
- --
- Matthew Saltzman
- Clemson University Math Sciences
- mjs@clemson.edu
-